<html lang="en">
<head>
<title>Installing GCC: Building</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Installing GCC: Building">
<meta name="generator" content="makeinfo 4.7">
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.

   Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no
Invariant Sections, the Front-Cover texts being (a) (see below), and
with the Back-Cover Texts being (b) (see below).  A copy of the
license is included in the section entitled "GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

     A GNU Manual

(b) The FSF's Back-Cover Text is:

     You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development.-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc { font-variant:small-caps }
  span.roman { font-family: serif; font-weight: normal; } 
--></style>
</head>
<body>
<h1 class="settitle">Installing GCC: Building</h1>
<a name="index-Installing-GCC_003a-Building-1"></a>
Now that GCC is configured, you are ready to build the compiler and
runtime libraries.

   <p>We <strong>highly</strong> recommend that GCC be built using GNU make;
other versions may work, then again they might not. 
GNU make is required for compiling GNAT (the Ada compiler) and the Java
runtime library.

   <p>(For example, many broken versions of make will fail if you use the
recommended setup where <var>objdir</var> is different from <var>srcdir</var>. 
Other broken versions may recompile parts of the compiler when
installing the compiler.)

   <p>Some commands executed when making the compiler may fail (return a
nonzero status) and be ignored by <span class="command">make</span>.  These failures, which
are often due to files that were not found, are expected, and can safely
be ignored.

   <p>It is normal to have compiler warnings when compiling certain files. 
Unless you are a GCC developer, you can generally ignore these warnings
unless they cause compilation to fail.

   <p>On certain old systems, defining certain environment variables such as
<span class="env">CC</span> can interfere with the functioning of <span class="command">make</span>.

   <p>If you encounter seemingly strange errors when trying to build the
compiler in a directory other than the source directory, it could be
because you have previously configured the compiler in the source
directory.  Make sure you have done all the necessary preparations.

   <p>If you build GCC on a BSD system using a directory stored in an old System
V file system, problems may occur in running <span class="command">fixincludes</span> if the
System V file system doesn't support symbolic links.  These problems
result in a failure to fix the declaration of <code>size_t</code> in
<span class="file">sys/types.h</span>.  If you find that <code>size_t</code> is a signed type and
that type mismatches occur, this could be the cause.

   <p>The solution is not to use such a directory for building GCC.

   <p>When building from CVS or snapshots, or if you modify parser sources,
you need the Bison parser generator installed.  Any version 1.25 or
later should work; older versions may also work.  If you do not modify
parser sources, releases contain the Bison-generated files and you do
not need Bison installed to build them.

   <p>When building from CVS or snapshots, or if you modify Texinfo
documentation, you need version 4.2 or later of Texinfo installed if you
want Info documentation to be regenerated.  Releases contain Info
documentation pre-built for the unmodified documentation in the release.

<h3 class="section"><a name="TOC0"></a>0.1 Building a native compiler</h3>

<p>For a native build issue the command <span class="samp">make bootstrap</span>.  This
will build the entire GCC system, which includes the following steps:

     <ul>
<li>Build host tools necessary to build the compiler such as texinfo, bison,
gperf.

     <li>Build target tools for use by the compiler such as binutils (bfd,
binutils, gas, gprof, ld, and opcodes)
if they have been individually linked
or moved into the top level GCC source tree before configuring.

     <li>Perform a 3-stage bootstrap of the compiler.

     <li>Perform a comparison test of the stage2 and stage3 compilers.

     <li>Build runtime libraries using the stage3 compiler from the previous step.

   </ul>

   <p>If you are short on disk space you might consider <span class="samp">make
bootstrap-lean</span> instead.  This is identical to <span class="samp">make
bootstrap</span> except that object files from the stage1 and
stage2 of the 3-stage bootstrap of the compiler are deleted as
soon as they are no longer needed.

   <p>If you want to save additional space during the bootstrap and in
the final installation as well, you can build the compiler binaries
without debugging information as in the following example.  This will save
roughly 40% of disk space both for the bootstrap and the final installation. 
(Libraries will still contain debugging information.)

<pre class="example">          make CFLAGS='-O' LIBCFLAGS='-g -O2' \
            LIBCXXFLAGS='-g -O2 -fno-implicit-templates' bootstrap
</pre>
   <p>If you wish to use non-default GCC flags when compiling the stage2 and
stage3 compilers, set <code>BOOT_CFLAGS</code> on the command line when doing
<span class="samp">make bootstrap</span>.  Non-default optimization flags are less well
tested here than the default of <span class="samp">-g -O2</span>, but should still work. 
In a few cases, you may find that you need to specify special flags such
as <span class="option">-msoft-float</span> here to complete the bootstrap; or, if the
native compiler miscompiles the stage1 compiler, you may need to work
around this, by choosing <code>BOOT_CFLAGS</code> to avoid the parts of the
stage1 compiler that were miscompiled, or by using <span class="samp">make
bootstrap4</span> to increase the number of stages of bootstrap.

   <p>If you used the flag <span class="option">--enable-languages=...</span> to restrict
the compilers to be built, only those you've actually enabled will be
built.  This will of course only build those runtime libraries, for
which the particular compiler has been built.  Please note,
that re-defining <span class="env">LANGUAGES</span> when calling <span class="samp">make bootstrap</span>
<strong>does not</strong> work anymore!

   <p>If the comparison of stage2 and stage3 fails, this normally indicates
that the stage2 compiler has compiled GCC incorrectly, and is therefore
a potentially serious bug which you should investigate and report.  (On
a few systems, meaningful comparison of object files is impossible; they
always appear &ldquo;different&rdquo;.  If you encounter this problem, you will
need to disable comparison in the <span class="file">Makefile</span>.)

<h3 class="section"><a name="TOC1"></a>0.2 Building a cross compiler</h3>

<p>We recommend reading the
<a href="http://www.objsw.com/CrossGCC/">crossgcc FAQ</a>
for information about building cross compilers.

   <p>When building a cross compiler, it is not generally possible to do a
3-stage bootstrap of the compiler.  This makes for an interesting problem
as parts of GCC can only be built with GCC.

   <p>To build a cross compiler, we first recommend building and installing a
native compiler.  You can then use the native GCC compiler to build the
cross compiler.  The installed native compiler needs to be GCC version
2.95 or later.

   <p>Assuming you have already installed a native copy of GCC and configured
your cross compiler, issue the command <span class="command">make</span>, which performs the
following steps:

     <ul>
<li>Build host tools necessary to build the compiler such as texinfo, bison,
gperf.

     <li>Build target tools for use by the compiler such as binutils (bfd,
binutils, gas, gprof, ld, and opcodes)
if they have been individually linked or moved into the top level GCC source
tree before configuring.

     <li>Build the compiler (single stage only).

     <li>Build runtime libraries using the compiler from the previous step. 
</ul>

   <p>Note that if an error occurs in any step the make process will exit.

<h3 class="section"><a name="TOC2"></a>0.3 Building in parallel</h3>

<p>You can use <span class="samp">make bootstrap MAKE="make -j 2" -j 2</span>, or just
<span class="samp">make -j 2 bootstrap</span> for GNU Make 3.79 and above, instead of
<span class="samp">make bootstrap</span> to build GCC in parallel. 
You can also specify a bigger number, and in most cases using a value
greater than the number of processors in your machine will result in
fewer and shorter I/O latency hits, thus improving overall throughput;
this is especially true for slow drives and network filesystems.

<h3 class="section"><a name="TOC3"></a>0.4 Building the Ada compiler</h3>

<p>In order to build GNAT, the Ada compiler, you need a working GNAT
compiler (GNAT version 3.13 or later, or GCC version 3.1 or later),
since the Ada front end is written in Ada (with some
GNAT-specific extensions), and GNU make.

   <p>However, you do not need a full installation of GNAT, just the GNAT
binary <span class="file">gnat1</span>, a copy of <span class="file">gnatbind</span>, and a compiler driver
which can deal with Ada input (by invoking the <span class="file">gnat1</span> binary). 
You can specify this compiler driver by setting the <span class="env">ADAC</span>
environment variable at the configure step.  <span class="command">configure</span> can
detect the driver automatically if it has got a common name such as
<span class="command">gcc</span> or <span class="command">gnatgcc</span>.  Of course, you still need a working
C compiler (the compiler driver can be different or not). 
<span class="command">configure</span> does not test whether the GNAT installation works
and has a sufficiently recent version; if too old a GNAT version is
installed, the build will fail unless <span class="option">--enable-languages</span> is
used to disable building the Ada front end.

   <p>Additional build tools (such as <span class="command">gnatmake</span>) or a working GNAT
run-time library installation are usually <em>not</em> required.  However,
if you want to bootstrap the compiler using a minimal version of GNAT,
you have to issue the following commands before invoking <span class="samp">make
bootstrap</span> (this assumes that you start with an unmodified and consistent
source distribution):

<pre class="example">         cd <var>srcdir</var>/gcc/ada
         touch treeprs.ads [es]info.h nmake.ad[bs]
</pre>
   <p>At the moment, the GNAT library and several tools for GNAT are not built
by <span class="samp">make bootstrap</span>.  You have to invoke
<span class="samp">make gnatlib_and_tools</span> in the <var>objdir</var><span class="file">/gcc</span>
subdirectory before proceeding with the next steps.

   <p>For example, you can build a native Ada compiler by issuing the
following commands (assuming <span class="command">make</span> is GNU make):

<pre class="example">         cd <var>objdir</var>
         <var>srcdir</var>/configure --enable-languages=c,ada
         cd <var>srcdir</var>/gcc/ada
         touch treeprs.ads [es]info.h nmake.ad[bs]
         cd <var>objdir</var>
         make bootstrap
         cd gcc
         make gnatlib_and_tools
         cd ..
</pre>
   <p>Currently, when compiling the Ada front end, you cannot use the parallel
build feature described in the previous section.

   <p><hr />
<p><a href="./index.html">Return to the GCC Installation page</a>

<!-- ***Testing***************************************************************** -->
<!-- ***Final install*********************************************************** -->
<!-- ***Binaries**************************************************************** -->
<!-- ***Specific**************************************************************** -->
<!-- ***Old documentation****************************************************** -->
<!-- ***GFDL******************************************************************** -->
<!-- *************************************************************************** -->
<!-- Part 6 The End of the Document -->
</body></html>

